"use strict";
// 发送邮件模块
const nodemailer = require("nodemailer");

// 封装email函数
module.exports = async function main(email, message) {
    let testAccount = await nodemailer.createTestAccount();

    let transporter = nodemailer.createTransport({
        host: "smtp.qq.com", // 发送邮件的服务器
        port: 465, // 端口
        secure: true, // true 默认是 465端口, false 就是其它端口
        auth: {
            user: "2490179721@qq.com", // 发送者邮箱
            pass: "ilkhxagtixtueceg", // 发送者邮箱授权码
        },
    });

    // 发送邮箱配置项
    let info = await transporter.sendMail({
        from: `"Fred Foo 👻" < 2490179721@qq.com >`, // 发送者邮箱
        to: email, // 接收者邮箱
        subject: "Hello ✔ 对方留言", // 邮件主题
        text: message, // 邮件内容
        // html: "<b>Hello world?</b>", // html body
    });

    // console.log("Message sent: %s", info.messageId);
    // Message sent: <b658f8ca-6296-ccf4-8306-87d57a0b4321@example.com>

    // Preview only available when sending through an Ethereal account
    // console.log("Preview URL: %s", nodemailer.getTestMessageUrl(info));
    // Preview URL: https://ethereal.email/message/WaQKMgKddxQDoou...
};

// main().catch(console.error);

// main().catch(console.error);